<template>
	<view>
		<u-navbar :is-back="false" title="客服" :border-bottom="false"></u-navbar>
		
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="level" :arrow="false" title="客服电话" :value="sj"  @click="callPhoneNumber"></u-cell-item>
				<u-cell-item icon="level" :arrow="false" title="微信客服" :value="wx"  @click="fzwx"></u-cell-item>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	import config from "@/common/config.js" // 全局配置文件
	export default {
		data() {
			return {
				avatar: '',
				show:true,
				navList:[
				   {name:"我的兑换",icon:"checkmark-circle",url:"pages/center/history"},
				   {name:"积分记录",icon:"heart",url:"pages/center/heart"},
				   // {name:"购买记录",icon:"order",url:"pages/center/order"},
				   {name:"问题反馈",icon:"info-circle"}
				],
				sj:'',
				wx:''
			}
		},
		onLoad() {
			uni.$on('updateAvatar', (obj) => {
				// 获取数据
				this.updateAvatar();
			})
			this.getData()
		},
		onUnload() {
			// 移除监听事件  
			uni.$off('updateAvatar');
		},
		onShow(){
			// 检查token
			this.checkToken();
		},
		methods: {
			logout() {
				// 登录成功修改token与用户信息
				this.$u.vuex('vuex_token', '');
				this.$u.vuex('vuex_user', {});
				this.$u.route('/pages/login/login')
			},
			getData(){
				let url = "/api/sp/dataList";
				this.$u.get(url).then(res => {
					for (let i = 0; i < res.data.length; i++) {
						let item = res.data[i]
						if(item.code === 'phone'){
							this.sj = item.dataVar.replace('<p>','').replace('</p>','')
						}
						if(item.code === 'wx'){
							this.wx = item.dataVar.replace('<p>','').replace('</p>','')
						}
					}
				});
			},
			profile(){
				this.$u.route('/pages/profile/profile')
			},
			setting(){
				this.$u.route('/pages/profile/setting')
			},
			//拨打固定电话
			callPhoneNumber() {
				uni.makePhoneCall({
					phoneNumber: this.sj,
				});
			},
			problem(){
				this.$u.route({
					url: 'pages/login/problem'
				})
			},
			// 关于作者
			aboutMe() {
				this.$u.route('/pages/profile/aboutMe')
			},
			checkToken(){
				// 判断是否有token
				let lifeData = uni.getStorageSync('lifeData');
				let token = lifeData.vuex_token
				if(!token){
					// 没有token 则跳转到登录
					return uni.reLaunch({
						url:'../login/login'
					})
				}else{
					// 判断Token是否有效
					let url = "/api/sp/getInfo";
					this.$u.get(url,{
						token:token
					}).then(obj => {
						if(obj.data){
							this.$u.vuex('vuex_user', obj.data);
						}
					});
				}
			},
			code(){
				this.$mytip.toast('敬请期待')
			},
			clickNav(url){
				if(url){
					this.$u.route(url);
				}else{
					this.$mytip.toast('敬请期待')
				}
				// this.$mytip.toast('未完成')
			},
			updateAvatar(){
				this.avatar = ''
			},
			fzwx() {
							// 设置系统剪贴板的内容
							uni.setClipboardData({
								data: this.wx,
								success: () => {
									uni.showToast({
										title: '复制成功'
									})
								}
							})
						}
		}
	}
</script>

<style lang="scss">
.user-box{
	background-color: #fff;
	justify-content: space-between;
}

.center-nav{
	background-color: #FFFFFF;
	margin-top: 30rpx;
	padding: 30rpx 0;
	border-radius: 8px;
	.tabName{
		color: #606266;
		font-size: 26rpx;
		padding-top: 10rpx;
	}
}

.qiandao{
	color: #606266;
	font-size: 24rpx;
	margin-right: 24rpx;
	margin-top: 54rpx;
	justify-content:center;
	align-items: center;
}

.clearBtn{
		margin:0;
		padding: 0;
		line-height: 1;
		background-color: #FFFFFF;
}

.clearBtn::after{
	position: unset !important;
	border: unset;
}
</style>